
package adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ui.activity.poscontrol.beanmodel.PosAuthRecordBean;
import util.SysUtils;


/**
 * 自助报单历史记录列表适配器
 * Created by chenjian on 19/2/27
 */
public class PosAuthRecordAdapter extends DelegateAdapter.Adapter<PosAuthRecordAdapter.ProfitVH> {

    private final Context mContext;
    private List<PosAuthRecordBean.RecordsBean> datas = new ArrayList<>();

    public PosAuthRecordAdapter(Context context, List<PosAuthRecordBean.RecordsBean> data) {
        mContext = context;
        datas = data;
    }

    public void setData(List<PosAuthRecordBean.RecordsBean> data) {
        datas = data;
        notifyDataSetChanged();
    }


    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public ProfitVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProfitVH(LayoutInflater.from(mContext).inflate(R.layout.layout_posauthrecord, viewGroup, false));
    }


    @Override
    public void onBindViewHolder(@NonNull ProfitVH holder, int position) {
        if (position < 0 || position >= datas.size()) {
            return;
        }
        holder.name.setText(datas.get(position).getMerchantName());
        holder.time.setText( SysUtils.sf.format(new Date(datas.get(position).getGmtCreate())));
        holder.snno.setText(datas.get(position).getPosInstanceSn());

//:2:审核中；3：审核失败；4：已开通；5：已激活；6：已达标；
        String status ="";
        if(datas.get(position).getIsPassed().equals("1")){
            status  = "未提交";
            holder.status.setTextColor(mContext.getResources().getColor(R.color.blue_0ca6f0));
        }else if(datas.get(position).getIsPassed().equals("2")){
            status  = "审核中";
            holder.status.setTextColor(mContext.getResources().getColor(R.color.blue_0ca6f0));
        }else if(datas.get(position).getIsPassed().equals("3")){
            status  = "审核失败";
            holder.status.setTextColor(mContext.getResources().getColor(R.color.red_fe3333));
        }else if(datas.get(position).getIsPassed().equals("4")){
            status  = "已开通";
            holder.status.setTextColor(mContext.getResources().getColor(R.color.blue_0ca6f0));
        }else if(datas.get(position).getIsPassed().equals("5")){
            status  = "已激活";
            holder.status.setTextColor(mContext.getResources().getColor(R.color.blue_0ca6f0));
        }else if(datas.get(position).getIsPassed().equals("6")){
            status  = "已达标";
            holder.status.setTextColor(mContext.getResources().getColor(R.color.blue_0ca6f0));
        }
        holder.status.setText(status);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ProfitVH extends RecyclerView.ViewHolder {
        TextView name;
        TextView time;
        TextView snno;
        TextView status;

        ProfitVH(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.posrecord_name);
            time = itemView.findViewById(R.id.posrecord_time);
            snno = itemView.findViewById(R.id.posrecord_snno);
            status = itemView.findViewById(R.id.posrecord_status);

        }
    }
}
